<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="400" destroy-on-close @closed="$emit('closed')">
		<el-container v-loading="loading">
			<el-main style="padding:0 20px 20px 20px">
				<el-form ref="dialogForm" :model="form" :rules="rules" label-width="100px" label-position="left">
					<el-form-item label="排序号">
						<el-input-number v-model="form.sortNo" placeholder="=排序号"></el-input-number>
					</el-form-item>
					<el-form-item label="模块名称" prop="title">
						<el-input v-model="form.title" placeholder="模块名称"></el-input>
					</el-form-item>
					<el-form-item label="模块标识" prop="module">
						<el-input v-model="form.module" placeholder="模块标识"></el-input>
					</el-form-item>
					<el-form-item label="是否开启" prop="status">
						<el-switch v-model="form.status" active-value="1" inactive-value="0"></el-switch>
					</el-form-item>
					<el-form-item label="备注">
						<el-input v-model="form.remark" placeholder="备注" maxlength="95"></el-input>
					</el-form-item>
				</el-form>
			</el-main>
			<el-footer style="text-align: center">
				<el-button type="primary" :loading="isSaveing" @click="submit">保存</el-button>
				<el-button @click="visible=false">取消</el-button>
			</el-footer>
		</el-container>

	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			loading: false,
			mode: "add",
			titleMap: {
				add: '新增',
				edit: '编辑'
			},
			form: {
				configId:"",
				sortNo:0,
				title:"",
				module:'',
				insertRole:"0",
				deleteRole:"0",
				updateRole:"0",
				queryRole:"0",
				status:'1',
				remark:''
			},
			visible: false,
			isSaveing: false,
			rules: {
				title: [
					{required: true, message: '模块名称不能为空', trigger: 'blur'}
				],
				module: [
					{required: true, message: '模块标识不能为空', trigger: 'blur'}
				]
			},
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if(this.mode=="add")
					{
						res = await this.$API.system.sysSecurity.insertSysSecurityConfig.post(this.form);
					}else if(this.mode=="edit")
					{
						res = await this.$API.system.sysSecurity.updateSysSecurityConfig.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		//表单注入数据
		setData(data) {
			this.form.configId=data.configId;
			this.form.sortNo=data.sortNo;
			this.form.title=data.title;
			this.form.module = data.module
			this.form.status = data.status
			this.form.remark=data.remark
		}
	}
}
</script>

<style>
</style>
